a = 10
b = 'hello,world'

# (1) 列表,[], list()
c = ['张三', 18, '女']
c1 = ['女', 18, '张三']
print('姓名：' + c[0])
print('年龄：' + str(c[1]))
print('性别：' + c[2])

# (2) 字典，{}, dict()
d = {
    'age': 18,
    'name': '张三',  # key : value ，键:值
     'gender': '女'
} # json数据格式

print('姓名:', d['name'])
print('年龄:', d['age'])
print('性别:', d['gender'])

e1, e2 = (1, 2)  # 元组
f1, f2 = ('a1', 'a2')


# (3) 类的方式存储一个学生信息

# (3.1) 创建自定义类型(和列表、字典在本质上是一样的)
class Student:
    def __init__(self):
        self.name = ''
        self.age = 0
        self.gender = ''
        self.phone = ''


# (3.2) 如何使用自定义类型
g = Student()  # 通过实例化方式使用一个类
g.name = '张三'
g.age = 18
g.gender = '女'
g.phone = '133099090'

print('姓名:', g.name)
print('性别:', g.gender)
print('年龄:', g.age)
print('手机号:', g.phone)

g2 = Student()
g2.name = '李四'
g2.age = 14
g2.gender = '女'
g2.phone = '13999887777'


# (4) 利用类的方式存储书名等信息。
class Book:
    def __init__(self):
        self.name = ''
        self.price = 0.0
        self.owner = ''


my_book = Book()
my_book.name = 'Python工程实践'
my_book.price = 20.0
my_book.owner = '张三'

his_book = Book()
his_book.name = 'Python程序设计'
his_book.price = 20.0
his_book.owner = '李四'

books = []
books.append(my_book)
books.append(his_book)

for item in books:
    print('书名：', item.name)
    print('价格：', item.price)
    print('所有者：', item.owner)
    print('-' * 20)



# (5) 每一本书采用字典的方式存储数据，如何存储两本书的信息以及如何遍历
book1 = {
    'name':'Python',
    'price':'10',
    'owner':'alice',
}
book2 = {
    'name': 'Python2',
    'price': '20',
    'owner': 'bob',
}
books2 = []
books2.append(book1)
books2.append(book2)

for item in books2:
    print('书名：', item['name'])
    print('价格：', item['price'])
    print('所有者：', item['owner'])
    print('-' * 20)



